﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;

namespace WebPattern.Core.Security
{
    public class WebPatternAuthorizeAttribute : AuthorizeAttribute
    {
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            if (filterContext.HttpContext.User.Identity.IsAuthenticated && !filterContext.HttpContext.User.IsInRole(Roles))
            {
                UrlHelper urlH = new UrlHelper(filterContext.RequestContext);
                RedirectResult result = new RedirectResult(urlH.Action("RestrictedAccess", "Account"));
                filterContext.Result = result;
            }
            else
            {
                base.HandleUnauthorizedRequest(filterContext);
            }
        }
    }
}
